package com.allwees.bs.module.pms.req.query;

import com.allwees.bs.core.modelbase.req.QueryReq;
import com.allwees.bs.core.modelbase.validate.ValidateItem;
import com.allwees.bs.module.pms.vo.ProductAuditLogVo;
import com.allwees.core.common.constant.EAuditResult;
import com.allwees.core.common.constant.EStatus;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;

/**
 * Product查询条件
 *
 * @author yangylsky
 * @since 2019-12-18
 *
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ProductAuditLogQueryReq extends QueryReq<ProductAuditLogVo> {
	private String productUuid;

	private EAuditResult auditResult;

	private boolean top1 = true;

	@Override
	public ValidateItem[] getValidateItems() {
		return ArrayUtils.addAll(super.getValidateItems(),
				new ValidateItem(StringUtils.isBlank(productUuid), "商品uuid不能为空"));
	}

	public List<Integer> getActionStatus() {
		if(auditResult == null) {
			return ListUtils.union(_getActionStatus(EAuditResult.APPROVED), _getActionStatus(EAuditResult.REJECTED));
		}
		return _getActionStatus(auditResult);
	}

	private List<Integer> _getActionStatus(EAuditResult auditResult) {
		switch(auditResult) {
			case APPROVED:
				return Arrays.asList(EStatus.AUDIT_APPROVED.value());
			case REJECTED:
				return Arrays.asList(EStatus.AUDIT_REJECTED.value());
			default:
				throw new IllegalArgumentException();
		}
	}
}
